// const { DefinePlugin } = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')

module.exports = {
  mode: 'development',
  entry: './index.js',
  // watch: true, // watch for changes
  output: {
    filename: 'main.js',
    path: __dirname + '/dist', // __dirname is the current directory
    // assetModuleFilename: 'images/[name][ext]'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['babel-loader'],
      },
    ],
  },
  plugins: [
    new CleanWebpackPlugin(), // 清除 dist 文件夹
    new HtmlPlugin({
      title: 'Mini Vue',
      filename: 'index.html',
      favicon: './public/favicon.ico',
      template: './public/index.html',
      minify: {
        // removeAttributeQuotes: true, // 去掉属性的双引号
        // collapseWhitespace: true, // 去掉空格
        removeComments: true, // 去掉注释
      },
    }),
    // new CopyPlugin({
    //   patterns: [
    //     {
    //       from: 'public',
    //       globOptions: {
    //         ignore: ['**/index.html', '**/favicon.ico'],
    //       },
    //       // to: 'images',
    //     },
    //   ],
    // }),
  ],
  devServer: {
    hot: true, // 开启热更新
    // contentBase: './dist', // 告诉服务器从哪里提供内容
    port: 7000, // 设置端口号
  },
  target: 'web', // 开启 webpack-dev-server
}
